use modular_bitfield_msb::prelude::*;

#[bitfield]
#[derive(Debug, Clone, Copy)]
pub struct BlockHeader {
    block_size_field0:B5,
    block_type:BlockType,
    last_block:bool,
    block_size_field1:B8,
    block_size_field2:B8,
}

impl BlockHeader {
    pub fn block_size(&self) -> u32 {
        u32::from(self.block_size_field0())
        | (u32::from(self.block_size_field1()) << 5)
        | (u32::from(self.block_size_field2()) << 13)
    }

    pub fn get_block_type(&self) -> BlockType {
        self.block_type()
    }

    pub fn is_last_block(&self) -> bool {
        self.last_block()
    }
}


#[derive(Debug,BitfieldSpecifier)]
#[bits=2]
pub enum BlockType {
    Raw = 0,
    Rle = 1,
    Compressed = 2,
    Reversed = 3,
}